#include "BaseType.h"
#include "list.h"

/*****************************************************************************
 *
 *  List Functions
 *
 ****************************************************************************/
void InitListHead(PLIST_ENTRY list_head)
{
	list_head->prev = list_head;
	list_head->next = list_head;
}

void InsertListTail( PLIST_ENTRY list_head, PLIST_ENTRY list_entry )
{
	PLIST_ENTRY list_tail;
	list_tail = list_head->prev;
	list_tail->next = list_entry;
	list_entry->prev = list_tail;
	list_head->prev = list_entry;
	list_entry->next = list_head;
}

void RemoveListEntry( PLIST_ENTRY list_entry )
{
	list_entry->prev->next = list_entry->next;
	list_entry->next->prev = list_entry->prev;
	list_entry->prev = list_entry;
	list_entry->next = list_entry;
}

PLIST_ENTRY RemoveListHead( PLIST_ENTRY list_head )
{
	PLIST_ENTRY ret_list_entry;
	ret_list_entry = list_head->next;
	list_head->next = ret_list_entry->next;
	ret_list_entry->next->prev = list_head;
	ret_list_entry->next = ret_list_entry;
	ret_list_entry->prev = ret_list_entry;
	return ret_list_entry;
}

BOOL ListIsEmpty( PLIST_ENTRY list_head )
{
	if ( ( list_head->prev == list_head ) || ( list_head->next == list_head ) ){
		return TRUE;
	}else{
		return FALSE;
	}
}
